<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>




  <link href="//fonts.googleapis.com/css?family=Lato:300,400,700,400italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">



<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=0.5.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="天生DR,DR" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=0.5.0" />






<meta name="description" content="我跑啊跑啊跑 为的就是赶上那个被寄予厚望的自己">
<meta property="og:type" content="website">
<meta property="og:title" content="天生DR">
<meta property="og:url" content="http://www.dr17.me/page/2/">
<meta property="og:site_name" content="天生DR">
<meta property="og:description" content="我跑啊跑啊跑 为的就是赶上那个被寄予厚望的自己">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="天生DR">
<meta name="twitter:description" content="我跑啊跑啊跑 为的就是赶上那个被寄予厚望的自己">




<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: 'Author'
    }
  };
</script>

  <title> 天生DR </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="">

  








  
  
    
  

  <div class="container one-collumn sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天生DR</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">当上帝亲吻大地的时候于是DR出现了 他是上帝赐予人类最好的礼物</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu ">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-home fa-fw"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-archive fa-fw"></i> <br />
            
            Archives
          </a>
        </li>
      

      
      
      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">

    

    
    

    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/01/30/usedTools/" itemprop="url">
                  Mac常用系统以及开发软件
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-01-30T10:01:29+08:00" content="Jan 30 2015">
              Jan 30 2015
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Mac流常用工具/" itemprop="url" rel="index">
                    <span itemprop="name">Mac流常用工具</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <ul>
<li><p>替代Finder 的ForkLift<br><img src="/images/forklift.png" alt="创建Aggregate Target"></p>
</li>
<li><p>替代终端的Fish Shell<br><img src="/images/fishshell.png" alt="创建Aggregate Target"></p>
</li>
<li><p>文档查看软件 Dash<br><img src="/images/dash.png" alt="创建Aggregate Target"><br><img src="/images/dash_ios.png" alt="创建Aggregate Target"></p>
</li>
<li><p>前端利器WebStorm  而且最新的webstorm 可以支持 断点调试了<br><img src="/images/webstorm.png" alt="创建Aggregate Target"><br><img src="/images/webstorm_1.png" alt="创建Aggregate Target"></p>
</li>
<li><p>Github出品 Atom<br><img src="/images/atom.png" alt="创建Aggregate Target"></p>
</li>
<li><p>其他同学有推荐的可以在下边留言哈  这是个分享的世界….</p>
</li>
</ul>

          
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/01/27/XCTest/" itemprop="url">
                  UnitTest ios 学习笔记
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-01-27T14:21:29+08:00" content="Jan 27 2015">
              Jan 27 2015
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/单元测试/" itemprop="url" rel="index">
                    <span itemprop="name">单元测试</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="运行第一个单元测试：">运行第一个单元测试：</h2>
<ul>
<li><p>在Xcode 5中新建一个工程默认自带一个单元测试的文件夹，IDE自动生成了一个实现XCTestCase的.m文件，里面有一个失败测试(早期版本中实现的是SenTestCase，是苹果集成的第三方的，现在苹果建议使用新的XCTestCase)</p>
</li>
<li><p>测试函数的要求是：1.必须无返回值；2.以test开头</p>
</li>
<li><p>测试函数执行的顺序：以函数名中test后面的字符大小有关，比如-（void）test001XXX会先于<br>  -（void）test002XXX执行</p>
</li>
<li><p>运行单元测试的快捷键：CMD + U</p>
</li>
</ul>
<h2 id="各种断言测试：">各种断言测试：</h2>
<ul>
<li><p>XCTFail(format…) 生成一个失败的测试</p>
</li>
<li><p>XCTAssertNil(a1, format…) 为空判断， a1 为空时通过，反之不通过</p>
</li>
<li><p>XCTAssertNotNil(a1, format…) 不为空判断，a1不为空时通过，反之不通过</p>
</li>
<li><p>XCTAssert(expression, format…) 当expression求值为TRUE时通过</p>
</li>
<li><p>XCTAssertTrue(expression, format…) 当expression求值为TRUE时通过</p>
</li>
<li><p>XCTAssertFalse(expression, format…) 当expression求值为False时通过</p>
</li>
<li><p>XCTAssertEqualObjects(a1, a2, format…) 判断相等， [a1 isEqual:a2] 值为TRUE时通过，其中一个不为空时，不通过</p>
</li>
<li><p>XCTAssertNotEqualObjects(a1, a2, format…) 判断不等， [a1 isEqual:a2] 值为False时通过</p>
</li>
<li><p>XCTAssertEqual(a1, a2, format…) 判断相等（当a1和a2是 C语言标量、结构体或联合体时使用,实际测试发现NSString也可以）</p>
</li>
<li><p>XCTAssertNotEqual(a1, a2, format…) 判断不等（当a1和a2是 C语言标量、结构体或联合体时使用）</p>
</li>
<li><p>XCTAssertEqualWithAccuracy(a1, a2, accuracy, format…) 判断相等，（double或float类型）提供一个误差范围，当在误差范围（+/- accuracy ）以内相等时通过测试</p>
</li>
<li><p>XCTAssertNotEqualWithAccuracy(a1, a2, accuracy, format…) 判断不等，（double或float类型）提供一个误差范围，当在误差范围以内不等时通过测试</p>
</li>
<li><p>XCTAssertThrows(expression, format…) 异常测试，当expression发生异常时通过；反之不通过（很变态）</p>
</li>
<li><p>XCTAssertThrowsSpecific(expression, specificException, format…) 异常测试，当expression发生 specificException 异常时通过；反之发生其他异常或不发生异常均不通过</p>
</li>
<li><p>XCTAssertThrowsSpecificNamed(expression, specificException, exception_name, format…) 异常测试，当expression发生具体异常、具体异常名称的异常时通过测试，反之不通过</p>
</li>
<li><p>XCTAssertNoThrow(expression, format…) 异常测试，当expression没有发生异常时通过测试</p>
</li>
<li><p>XCTAssertNoThrowSpecific(expression, specificException, format…)异常测试，当expression没有发生具体异常、具体异常名称的异常时通过测试，反之不通过</p>
</li>
<li><p>XCTAssertNoThrowSpecificNamed(expression, specificException, exception_name, format…) 异常测试，当expression没有发生具体异常、具体异常名称的异常时通过测试，反之不通过</p>
</li>
</ul>

          
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/01/21/network_link_conditinder/" itemprop="url">
                  Network Link Conditioner
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-01-21T14:21:29+08:00" content="Jan 21 2015">
              Jan 21 2015
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/iOS-网络/" itemprop="url" rel="index">
                    <span itemprop="name">iOS 网络</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>在平时开发过程当中，很多时候我们要测试在网络环境非WIFI或者网络环境Very Bad的模拟，对于针对于此类需求  市面上成熟的产品在mac 端不多   DR之前使用的是speedlimit 用着还可以 但是后来换了新公司  最新的mac os 装不上  google之 发现Apple 在XCode6.1 的软件包中 搜索Network Link Conditioner</p>
<p><img src="http://7u2ibm.com1.z0.glb.clouddn.com/20150121_01.png" alt="开发者中心下载"></p>
<p><img src="http://7u2ibm.com1.z0.glb.clouddn.com/20150121_02.png" alt="下载成功后"></p>
<p><img src="http://7u2ibm.com1.z0.glb.clouddn.com/20150121_03.png" alt="在系统设置中找到此项"></p>
<p><img src="http://7u2ibm.com1.z0.glb.clouddn.com/20150121_04.png" alt="这就可以选择使用了"></p>
<p>有一篇文章 为Matt大神所写   <a href="http://nshipster.com/network-link-conditioner/" target="_blank" rel="external">传送门在此</a></p>
<p>对 我不是什么工程师 我只是大自然的代码搬运工  完毕 over</p>

          
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/01/14/ios_framework_package/" itemprop="url">
                  iOS项目中静态库Framework的打包
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-01-14T15:59:29+08:00" content="Jan 14 2015">
              Jan 14 2015
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/iOS/" itemprop="url" rel="index">
                    <span itemprop="name">iOS</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>iOS SDK自身的一些库大多使用Framework的形式提供。Framework的好处<s>都有啥，谁说对了就给他</s>：</p>
<ul>
<li>将头文件和库文件绑到一起，只要把Framework拖进项目，基本可以做到开箱即用；</li>
<li>可以将多个版本的库文件打包到Framework中，而且可以进行切换。</li>
</ul>
<p>本文简要介绍了如何手动打包一个Framework的方法。</p>
<h2 id="Framework的文件结构">Framework的文件结构</h2>
<p>Framework到底是个啥呢？其实它就是一个目录，里面包含了库文件和头文件，XCode通过这种统一的格式方便对库进行引用。</p>
<p>一个最小的Framework目录的结构如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><名称>.framework</名称></div><div class="line">    +-- Headers      # 头文件</div><div class="line">    |    +-- some.h</div><div class="line">    |    +-- another.h</div><div class="line">    +-- <名称>        # 对于静态库项目来说，这是一个.a文件，在framework中则跟framework的名称同名，无扩展名</名称></div></pre></td></tr></table></figure>

<p>其中，Headers目录和Framework同名库均可以做成软链接，以实现多版本共存。一个典型的多版本Framework的目录结构如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><名称>.framework</名称></div><div class="line">    +-- Headers --> 软链接至 Versions/Current/Headers</div><div class="line">    +-- <名称>   --> 软链接至 Versions/Current/<名称></名称></名称></div><div class="line">    +-- Versions</div><div class="line">        +-- Current --> 软链接至 VersionA</div><div class="line">        +-- VersionA</div><div class="line">        |   +-- Headers # 头文件实际位置</div><div class="line">        |   |   +-- some.h</div><div class="line">        |   |   +-- another.h</div><div class="line">        |   +-- <名称>   # 库文件实际位置</名称></div><div class="line">        +-- VersionB</div><div class="line">            +-- Headers</div><div class="line">            |   +-- some.h</div><div class="line">            |   +-- another.h</div><div class="line">            +-- <名称></名称></div></pre></td></tr></table></figure>

<p>所以，实际上我们只需要将静态库项目编译完成后的结果按照相应文件结构复制出来，就完成Framework的打包了 :D</p>
<h2 id="Framework打包实战：libWagon">Framework打包实战：libWagon</h2>
<p>了解了Framework的结构之后，我们可以很轻易地通过写一些shell脚本来自动化Framework的生成，并将其集成到XCode项目中。</p>
<p>首先，为静态库项目创建一个Target，类型选择Aggregate。</p>
<p><img src="/images/20150114-aggregate-target.png" alt="创建Aggregate Target"></p>
<p>这里我们先创建一个适用于真机的Framework包，名称就填写<code>WagonFrameworkIphone</code>。</p>
<p>在这个Target的Build Phases选项中，添加一个Run Script的Phase：</p>
<p><img src="/images/20150114-create-runscript-phase.gif" alt="创建Run Script Phase"></p>
<p>所有想关依赖构建完成后，就会执行这段shell脚本。为了保证方便使用bash扩展，指定使用<code>/bin/bash</code>来执行。</p>
<p>脚本的主要工作就是编译整个静态库项目，然后按照framework的文件结构复制文件。完整的脚本内容如下：</p>
<figure class="highlight shell-script"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="title">build_library</span></span> () {</div><div class="line">    xcrun xcodebuild -project <span class="string">"<span class="variable">${PROJECT_FILE_PATH}</span>"</span> \</div><div class="line">    -target Wagon \</div><div class="line">    -configuration <span class="string">"<span class="variable">${CONFIGURATION}</span>"</span> \</div><div class="line">    -sdk <span class="string">"iphoneos<span class="variable">${1}</span>"</span> \</div><div class="line">    -arch armv7 \</div><div class="line">    -arch armv7s \</div><div class="line">    -arch arm64</div><div class="line">}</div><div class="line"></div><div class="line">SDK_VERSION=`<span class="built_in">echo</span> <span class="variable">$SDK_NAME</span> | sed <span class="operator">-e</span> <span class="string">"s/[A-Za-z]//g"</span>`</div><div class="line"></div><div class="line"><span class="comment">#clean</span></div><div class="line">rm -rf build/Release-iphoneos</div><div class="line">rm -rf build/Wagon.framework</div><div class="line"></div><div class="line"><span class="comment">#build</span></div><div class="line">build_library <span class="string">"<span class="variable">${SDK_VERSION}</span>"</span></div><div class="line"></div><div class="line"><span class="comment">#pack</span></div><div class="line">mkdir -p <span class="string">"build/Wagon.framework"</span></div><div class="line">cp -r <span class="string">"build/Release-iphoneos/include/Wagon"</span> <span class="string">"build/Wagon.framework/Headers"</span></div><div class="line">cp <span class="string">"build/Release-iphoneos/libWagon.a"</span> <span class="string">"build/Wagon.framework/Wagon"</span></div></pre></td></tr></table></figure>

<p>通过<code>xcodebuild</code>生成的项目，生成结果都位于项目同级的<code>build/</code>目录下，直接复制文件即可。</p>
<p>同理，我们也可以为模拟器制作一个target，只需要修改脚本的一小部分：</p>
<figure class="highlight shell-script"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="title">build_library</span></span> () {</div><div class="line">    xcrun xcodebuild -project <span class="string">"<span class="variable">${PROJECT_FILE_PATH}</span>"</span> \</div><div class="line">    -target Wagon \</div><div class="line">    -configuration <span class="string">"<span class="variable">${CONFIGURATION}</span>"</span> \</div><div class="line">    -sdk <span class="string">"iphonesimulator<span class="variable">${1}</span>"</span> \</div><div class="line">    -arch i386 \</div><div class="line">    -arch x86_64</div><div class="line">}</div><div class="line"></div><div class="line">SDK_VERSION=`<span class="built_in">echo</span> <span class="variable">$SDK_NAME</span> | sed <span class="operator">-e</span> <span class="string">"s/[A-Za-z]//g"</span>`</div><div class="line"></div><div class="line"><span class="comment">#clean</span></div><div class="line">rm -rf build/Release-iphonesimulator</div><div class="line">rm -rf build/Wagon.framework</div><div class="line"></div><div class="line"><span class="comment">#build</span></div><div class="line">build_library <span class="string">"<span class="variable">${SDK_VERSION}</span>"</span></div><div class="line"></div><div class="line"><span class="comment">#pack</span></div><div class="line">mkdir -p <span class="string">"build/Wagon.framework"</span></div><div class="line">cp -r <span class="string">"build/Release-iphonesimulator/include/Wagon"</span> <span class="string">"build/Wagon.framework/Headers"</span></div><div class="line">cp <span class="string">"build/Release-iphonesimulator/libWagon.a"</span> <span class="string">"build/Wagon.framework/Wagon"</span></div></pre></td></tr></table></figure>

<h2 id="制作通用版本的库文件">制作通用版本的库文件</h2>
<p><a href="/2015/01/12/iOS_StaticLibrary/">前一篇文章</a>介绍了使用<code>lipo</code>工具将不同平台的二进制文件合成一个统一的fat binary的方法。</p>
<p>借此我们可以将真机使用的库文件和模拟器使用的库文件合并成一个<code>.a</code>文件放进framework中，即可实现一个framework打遍天下XD</p>
<p>再创建一个Aggregate Target，此时将之前建立的两个target拖进依赖列表中，这样在构建通用版本的库文件时，就会先构建前面的两个目标。</p>
<p>为目标添加shell脚本：</p>
<figure class="highlight shell-script"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="title">merge_library</span> () {</div><div class="line">    <span class="title">xcrun</span> lipo -create <span class="string">"<span class="variable">${1}</span>"</span> <span class="string">"<span class="variable">${2}</span>"</span> -output <span class="string">"<span class="variable">${3}</span>"</span></div><div class="line">}</div><div class="line"></div><div class="line">merge_library <span class="string">"build/Release-iphoneos/libWagon.a"</span> <span class="string">"build/Release-iphonesimulator/libWagon.a"</span> <span class="string">"build/libWagon.a"</span></div><div class="line"></div><div class="line"><span class="comment">#pack</span></div><div class="line">mkdir -p <span class="string">"build/Wagon.framework"</span></div><div class="line">cp -r <span class="string">"build/Release-iphoneos/include/Wagon"</span> <span class="string">"build/Wagon.framework/Headers"</span></div><div class="line">cp <span class="string">"build/libWagon.a"</span> <span class="string">"build/Wagon.framework/Wagon"</span></div></pre></td></tr></table></figure>

<p>这样就可以构建出通用的framework了。</p>
<h2 id="framework的使用">framework的使用</h2>
<p>基本上，只需要将framework拖进项目中就可以正常使用了。如果库本身还需要依赖一些外部组件，则需要在项目中引用那些外部的动态库或者framework；此外，为了支持ObjC的categories，还需要在链接选项中添加<code>-ObjC</code>。</p>

          
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/01/13/iOS_StaticLibrary/" itemprop="url">
                  iOS静态库
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-01-13T13:27:29+08:00" content="Jan 13 2015">
              Jan 13 2015
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/iOS/" itemprop="url" rel="index">
                    <span itemprop="name">iOS</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="开篇">开篇</h1>
<ul>
<li>在实际的编程过程中，通常会把一些公用函数制成函数库，供其它程序使用，有以下两点作用<br>    1 提搞了代码的复用； <br><br>  2 二则提搞了核心技术的保密程度。  <br><br><ul>
<li>所以在实际的项目开发中，经常会使用到函数库，函数库分为静态库和动态库两种。和多数人所熟悉的动态语言和静态语言一样，这里的所谓静态和动态是相对编译期和运行期的：静态库在程序编译时会被链接到目标代码中，程序运行时将不再需要改静态库；而动态库在程序编译时并不会被链接到目标代码中，只是在程序运行时才被载入，因为在程序运行期间还需要动态库的存在。</li>
</ul>
</li>
</ul>
<h1 id="静态库与动态库的区别">静态库与动态库的区别</h1>
<ul>
<li><p>有静态库就有动态库 而且单从字面意思上来说 貌似动态库更智能，更人性化更高大上一些  </p>
</li>
<li><p>使用静态库的好处</p>
<p> 1 模块化，分工合作</p>
<p> 2 避免少量改动经常导致大量的重复编译连接</p>
<p> 3 也可以重用，注意不是共享使用<br>   <br></p>
<ul>
<li><p>动态库使用有如下好处：</p>
<p>1 使用动态库，可以将最终可执行文件体积缩小</p>
<p>2 使用动态库，多个应用程序共享内存中得同一份库文件，节省资源</p>
<p>3 使用动态库，可以不重新编译连接可执行程序的前提下，更新动态库文件达到更新应用程序的目的。</p>
</li>
</ul>
</li>
</ul>
<p>  从1可以得出，将整个应用程序分模块，团队合作，进行分工，影响比较小等其他好处</p>
<p>   从2可以看出，其实动态库应该叫共享库，那么从这个意义上来说，苹果禁止iOS开发中使用动态库就可以理解了。</p>
<p>   因为在现在的iPhone，iPodTouch，iPad上面程序都是单进程的，也就是某一时刻只有一个进程在运行，那么你写个共享库共享给谁？（你使用的时候只有你一个应用程序存在，其他的应该被挂起了，即便是可以同时多个进程运行，别人能使用你的共享库里的东西吗？你这个是给你自己的程序定制的。）目前苹果的AppStore不支持模块更新，无法更新某个单独文件(除非自己写一个更新机制：有自己的服务端放置最新动态库文件)至于苹果为啥禁止ios开发使用动态库我想应该就是这个原因<del>~</del></p>
<h1 id="iOS允许的静态库">iOS允许的静态库</h1>
<ul>
<li><p>iPhone官方只支持静态库联编</p>
</li>
<li><p>创建静态库可能出于以下几个理由:<br><br>1.你想将一些你和你团队中的同事们经常使用的类打包并轻松的分享给周围其他人。 <br></p>
<p>2.你想让一些通用代码处于自己的掌控之下，以便于修复和升级。 <br></p>
<p>3.你想将库共享给其他人，但不想让他们看到你的源代码。 <br></p>
</li>
</ul>
<h1 id="制作静态库简单教程（一）">制作静态库简单教程（一）</h1>
<ul>
<li><p>创建一个新的project 工程<br> <img src="http://7u2ibm.com1.z0.glb.clouddn.com/ios_staticLibrary_1.png" alt=""></p>
<p> <img src="http://7u2ibm.com1.z0.glb.clouddn.com/ios_staticLibrary_2.png" alt=""><br>  <img src="http://7u2ibm.com1.z0.glb.clouddn.com/ios_staticLibrary_5.png" alt=""><br><img src="http://7u2ibm.com1.z0.glb.clouddn.com/ios_staticLibrary_4.png" alt=""><br><img src="http://7u2ibm.com1.z0.glb.clouddn.com/ios_staticLibrary_3.png" alt=""></p>
</li>
</ul>
<ul>
<li><p>在最后一张图中 我们是用模拟器打的静态库 这样的静态库打出来 只是支持i386 和 x86_64的 如果在真机中 会出现crash的情况 因为在armv7 和 armv7s 或者arm64下是不支持的</p>
</li>
<li><p>科普一下 </p>
</li>
<li><p>| i386,x86_64        | armv6|  armv7          | armv7s  |  arm64  |<br>|    :——————-:   |:——————-:|:——————-:  | :——-: | :——-:|<br>| 模拟器                 |iPhone,iPhone2| iPhone3GS      | iPhone5  |iPhone5s|<br>| 模拟器                |iPhone3G| iPhone4        | iPhone5c |iPhone6|<br>| 模拟器              |第一代和第二代iPod touch| iPhone4s       |          |iPhone6 Plus|</p>
</li>
<li><p>我们执行以下下面命令</p>
</li>
<li><p><code>lipo -info /Users/XXXXXXX/Library/Developer/Xcode/DerivedData/IOSStaticLibraryDemo-dmbcxhmspejfudccwkkiunuelxuf/Build/Products/Debug-iphonesimulator/libIOSStaticLibraryDemo.a</code></p>
</li>
<li><p>会出现以下输出<br><code>/Users/XXXXXXXX/Library/Developer/Xcode/DerivedData/IOSStaticLibraryDemo-dmbcxhmspejfudccwkkiunuelxuf/Build/Products/Debug-iphonesimulator/libIOSStaticLibraryDemo.a is architecture: x86_64</code></p>
</li>
<li><p>将此.a保存到某个目录下  并更改静态库名字libIOSStaticLibrarySimulator.a  <code>一会有用</code></p>
</li>
<li><p>so,我们下一步的任务 就很繁琐了 需要去xcode的build settings 里 查看archive 的参数<br><img src="http://7u2ibm.com1.z0.glb.clouddn.com/ios_staticLibrary_6.png" alt=""></p>
</li>
<li><p>可以看到Architetures 参数中 只有armv7 与 amd64 没有armv7s  也不知道是xcode6的bug 还是苹果觉得5和5c 的市场占有率不够多 而故意忽略这两款机型  </p>
<p>所以作为开发者 我们还是要加上这一个参数<br><img src="http://7u2ibm.com1.z0.glb.clouddn.com/ios_staticLibrary_7.gif" alt=""> </p>
</li>
<li><p>我们执行以下下面命令</p>
</li>
<li><p><code>lipo -info /Users/XXXXXXX/Library/Developer/Xcode/DerivedData/IOSStaticLibraryDemo-dmbcxhmspejfudccwkkiunuelxuf/Build/Products/Debug-iphonesimulator/libIOSStaticLibraryDemo.a</code></p>
</li>
<li><p>会出现以下输出</p>
</li>
<li><code>Architectures in the fat file: libIOSStaticLibraryDemo.a are: armv7 arm64 armv7s</code><ul>
<li>将此.a保存到刚才存放模拟器静态库的目录下  并更改静态库名字libIOSStaticLibrary_arm.a  <code>一会有用</code></li>
</ul>
</li>
</ul>
<ul>
<li><p>下一步 我们进行 lipo 合并<br>关于lipo 一般shell 都会自带这个命令 如果想深入了解lipo 的全部用法 请“男人”一下<br><img src="http://7u2ibm.com1.z0.glb.clouddn.com/ios_staticLibrary_8.png" alt=""></p>
</li>
<li><p><code>lipo -create libIOSStaticLibrary_Simulator.a libSQLite_arm.a -output libIOSStaticLibrary.a</code></p>
<p>  如果没有报错 证明没有错误 我们也可以用命令 验证一下 <code>lipo -info</code></p>
</li>
<li><code>Architectures in the fat file: libIOSStaticLibraryDemo.a are: x86_64 armv7 arm64 armv7s</code><br>因为我的mac 10.10是64位的 所以没有i386 </li>
</ul>

          
        
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    

  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="page-number current">2</span>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel  sidebar-panel-active ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://7u2ibm.com1.z0.glb.clouddn.com/avatar.png"
               alt="窦静轩" />
          <p class="site-author-name" itemprop="name">窦静轩</p>
          <p class="site-description motion-element" itemprop="description">我跑啊跑啊跑 为的就是赶上那个被寄予厚望的自己</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">15</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>
          
          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">12</span>
                <span class="site-state-item-name">categories</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">1</span>
                <span class="site-state-item-name">tags</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        <div class="links-of-author motion-element">
          
        </div>

      </section>

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="icon-next-heart fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">窦静轩</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="http://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>



      </div>
    </footer>

    <div class="back-to-top"></div>
  </div>

  


  



  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>

  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=0.5.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=0.5.0"></script>



  
  

  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=0.5.0"></script>



  



  



  
  

  
  


</body>
</html>
